<?php

App::import('Vendor', 'markdown' . DS . 'markdown');
App::import('Vendor', 'markdown' . DS . 'smartypants');

class MarkdownHelper extends AppHelper {

	var $helpers = array('Html','Form', 'Javascript');
	
	function myJSFile() {
		return $this->Javascript->link('showdown.js');
	}

	function parse($mdtext, $withSmarty = true) {
		$marked = Markdown($mdtext);
		if ($withSmarty) {
			$marked = Smartypants($marked);
		}
		return $this->output($marked);
	}
	
	function tt($name, $attributes = null) {
		if (is_null($attributes)) {
			$attributes = array();
		}
		if (is_string($attributes)) {
			$attributes = array('tag'=>$attributes);
		}
		$atts = array_merge(array(
			'tag'=>'div',
			'class'=>null,
			'id'=>$name
		), $attributes);
		extract($atts);
		$c = '';
		$i = '';
		if (!is_null($class)) {
			$c = " class='$class'";
		}
		if (!is_null($id)) {
			$i = " id='$id'";
		}
		return sprintf('<%s%s%s>%s</%1$s>', $tag, $i, $c, $this->parse(__($name,true)));
	}

}

?>